﻿using System;
using System.Diagnostics;
using System.Windows.Threading;

namespace Analyzer
{
    /// <summary>
    /// Provides access for the Dispatcher of the thread of the GUI for modelviews.
    /// </summary>
    /// <remarks>
    /// http://blogs.msdn.com/b/davidrickard/archive/2010/04/01/using-the-dispatcher-with-mvvm.aspx
    /// </remarks>
    [DebuggerStepThrough]
    public static class DispatchService
    {
        public static Dispatcher DispatchObject { get; set; }

        public static void Dispatch(Action action, params object[] args)
        {
            if (DispatchObject == null || DispatchObject.CheckAccess())
            {
                action();
            }
            else
            {
                DispatchObject.Invoke(action, args);
            }
        }
    }
}